<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{padding: 0;margin: 0;}
        .box{
            width: 150px;
            height: 150px;
            background-color: #6ff;
            margin: 100px;
        }
        .sub{
            width: 50px;
            height: 50px;
            background-color: #000;
            margin: 50px;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="sub"></div>
    </div>
</body>
<script>
        // 鼠标相关的事件
    // onclick       鼠标单击(鼠标左键 按下之后在松开)  
    // ondblclick    鼠标双击(鼠标左键 双击后在松开)
    // onmousedown   鼠标按下
    // onmousemove   鼠标移动
    // onmouseup     鼠标松开

    // onmouseover   鼠标划入
    // onmouseout    鼠标划出
    // onmouseenter  鼠标划入
    // onmouseleave  鼠标划出

    var box = document.getElementsByClassName("box")[0];

    // 鼠标单击(鼠标左键 按下之后在松开)  
    /* box.onclick = function(){
        console.log("click");
    } */

    // 鼠标双击(鼠标左键 双击后在松开)
    /* box.ondblclick = function(){
        console.log("dblclick");
    } */

    // onmousedown   鼠标按下
    /* box.onmousedown = function(event){  // e evt event对象(事件发生时相关的信息)
        console.log("mousedown",event.button);   // 左(0)  中(1)  右 (2)
        // console.log(event);
    } */
    
    // onmouseup     鼠标松开
    /* box.onmouseup = function(){
        console.log("mouseup");
    } */

    // onmousemove   鼠标移动
    /* box.onmousemove = function(){
        console.log("move");
    } */

    /* box.onmouseover = function(){
        console.log("over");
    }
    box.onmouseout = function(){
        console.log("out");
    } */

    // 问题 给父元素绑定onmouseover onmouseout ,滑过子元素时 会先触发划出 在触发划入

    // 解决方法:
    // 用onmouseenter 替换 onmouseover
    // 用onmouseleave 替换 onmouseout

    box.onmouseenter = function(){
        console.log("enter");
    }
    box.onmouseleave = function(){
        console.log("leave");
    }
</script>
</html>